package com.kkd.kkdapp.fragment;

import java.io.IOException;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;

import org.json.JSONException;
import org.json.JSONObject;

import pl.droidsonroids.gif.GifDrawable;

import android.app.Activity;
import android.app.Dialog;
import android.content.Intent;
import android.content.res.Resources.NotFoundException;
import android.graphics.Bitmap;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v4.app.Fragment;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.view.ViewGroup;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.AnimationSet;
import android.view.animation.AnimationUtils;
import android.view.animation.ScaleAnimation;
import android.widget.AbsListView;
import android.widget.AbsListView.OnScrollListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.RelativeLayout.LayoutParams;
import android.widget.TextView;

import com.google.gson.Gson;
import com.kkd.kkdapp.BaseApplication;
import com.kkd.kkdapp.R;
import com.kkd.kkdapp.Notify.Const;
import com.kkd.kkdapp.Notify.NotifyDispatcher;
import com.kkd.kkdapp.activity.FinancialPlanParticularsActivity;
import com.kkd.kkdapp.activity.HomeActivity;
import com.kkd.kkdapp.activity.KKDWebActivity;
import com.kkd.kkdapp.activity.LoginActivity;
import com.kkd.kkdapp.activity.MyActivity;
import com.kkd.kkdapp.activity.MyIncomeActivity;
import com.kkd.kkdapp.activity.SelectedBidActivity;
import com.kkd.kkdapp.activity.SignActivity;
import com.kkd.kkdapp.activity.WelfareActivity;
import com.kkd.kkdapp.adapter.IndexListAdapter;
import com.kkd.kkdapp.adapter.QuickEntryAdapter;
import com.kkd.kkdapp.db.app.model.Notice;
import com.kkd.kkdapp.http.entity.AllAccountInfo;
import com.kkd.kkdapp.http.entity.BannerTwoItem;
import com.kkd.kkdapp.http.entity.Home;
import com.kkd.kkdapp.http.entity.HomeData;
import com.kkd.kkdapp.http.entity.HomeRecommend;
import com.kkd.kkdapp.http.entity.HomeRecommendList;
import com.kkd.kkdapp.http.entity.HomeTender;
import com.kkd.kkdapp.http.entity.MyProperty;
import com.kkd.kkdapp.http.entity.QuickIn;
import com.kkd.kkdapp.http.entity.ReSign;
import com.kkd.kkdapp.http.entity.SingInData;
import com.kkd.kkdapp.http.manager.HttpCallBack;
import com.kkd.kkdapp.http.manager.KkdHttpMagager;
import com.kkd.kkdapp.listener.OnSingleClickListener;
import com.kkd.kkdapp.utils.AppUtil;
import com.kkd.kkdapp.utils.DialogUtils;
import com.kkd.kkdapp.utils.LogUtil;
import com.kkd.kkdapp.utils.PreferenceUtils;
import com.kkd.kkdapp.utils.SystemUtils;
import com.kkd.kkdapp.view.CountViewFloat;
import com.kkd.kkdapp.view.HomeHeadView;
import com.kkd.kkdapp.view.HomeQuickEntryView;
import com.kkd.kkdapp.view.RoundImageView;
import com.kkd.kkdapp.view.ScrollerLayout;
import com.kkd.kkdapp.view.ScrollerLayout.OnPullListener;
import com.kkd.kkdapp.view.ScrollerLayout.ScrollStateProvider;
import com.kkd.kkdapp.view.banner.CycleBannerView;
import com.kkd.kkdapp.view.banner.listener.OnBannerClickListener;
import com.kkd.kkdapp.view.banner.loader.KBannerImagLoader;
import com.kkd.kkdapp.view.VerticalFlipTextView;
import com.kkd.kkdapp.view.waveview.WaveView;
import com.kkd.kkdapp.view.xlistview.IndexScrollHeader;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.assist.FailReason;
import com.nostra13.universalimageloader.core.listener.ImageLoadingListener;

public class IndexFragment extends Fragment {

	private static final int DATA_OK = 1;
	private static final int DATA_FAIL = 2;
	private static final int MYPROPERTY_OK = 3;
	private static final int SIGN_OK = 4;
	private static final int SIGN_NO = 5;
	private static final int SIGN_ANIMATION = 10000001;
	private final int REPAIRSIGNIN_OK = 7;
	private final int REPAIRSIGNIN_NO = 8;

	private HomeActivity mCurActivity;
	private MyProperty myProperty;
	private RoundImageView myproperty_header;
	private CountViewFloat earnings_tv;
	// private AllConfig rAllConfig;
	private View mContentView;
	private CycleBannerView mBanner;
	private GifDrawable mGifDrawable;
	private LinearLayout linear_flag_sigining;
	private TextView sign_tv;
	private HomeHeadView mHeadView;
	private IndexScrollHeader mScrollHeadView;
	private RelativeLayout safe_img;
	private WaveView mWaveView;
	private HomeQuickEntryView mQuickEntry;
	public static ArrayList<String> mQuickEntryShow = new ArrayList<String>();
	private ArrayList<Notice> Notices = new ArrayList<Notice>();
	private VerticalFlipTextView mVFT;
	private RelativeLayout mVFT_RL;
	private RelativeLayout triangle;
	private Button login_bt;
	private ScrollerLayout mScrollerLayout;
	private ListView mListView;
	// private ListView mFooterListView;
	private View BidPast;
	private View GuangGao;

	// private ImageView mSaftyImg;
	private ImageView mSpecialActivityImg;
	private ImageView img_null;
	private ImageView index_bg;
	private TextView tv_null;
	private RelativeLayout title_bar_rl;
	private ImageView icon_happy_sign;
	private ImageView index_header_bg;
	private ImageView index_header_bg2;
	private HomeData mHomeData;
	private ArrayList<HomeRecommend> activities = new ArrayList<HomeRecommend>(); // 公告
	private ArrayList<HomeTender> bidList = new ArrayList<HomeTender>(); // 推荐标
	private ArrayList<QuickIn> mQuickIn = new ArrayList<QuickIn>(); // 快速入口
	private ArrayList<BannerTwoItem> bannerTwo = new ArrayList<BannerTwoItem>();
	private ArrayList<HomeRecommendList> recommendList = new ArrayList<HomeRecommendList>();

	// private IndexFooterListListAdapter mIndexFooterListListAdapter;
	private IndexListAdapter mIndexListAdapter;
	private QuickEntryAdapter mQuickEntryAdapter;
	private float startX;
	private float startY;
	private Dialog happyCoinCompleteProgressDialog; // 快乐币任务完成进度Dialog
	private SingInData singInData;
	private int statusCode;
	private String mDesc;
	private Dialog mDialog_signin;
	private Timer mSignTimer;
	private TimerTask mSignTimerTask;
	private Animation signAnimation;
	private Animation signAnimation2;
	private boolean flag_updateSign = true;
	private long time_signin_success;
	private RelativeLayout mTitleBar;
	private float alphaColor = 0.0f;
	private boolean downFlag = true;
	private ImageView no_Index_header_bg;

	private Handler mHandle = new Handler() {

		@Override
		public void handleMessage(Message msg) {
			switch (msg.what) {
			case DATA_OK:
				mScrollerLayout.clearState();
				bidList.clear();
				recommendList.clear();
				bannerTwo.clear();
				activities.clear();
				if (mHomeData.getActivities() != null) {
					activities.addAll(mHomeData.getActivities());
//					mBanner.notifyDataSetChanged();
					mBanner.update(activities);
				}
				if (mHomeData.getIsFindNew() == 1) {
					mCurActivity.find_dot.setVisibility(View.VISIBLE);
				} else {
					mCurActivity.find_dot.setVisibility(View.GONE);
				}
				if (!TextUtils.isEmpty(mHomeData.getIndexBackgroundUrl())) {

					ImageLoader.getInstance().displayGifImage(
							mHomeData.getIndexBackgroundUrl(), index_bg,
							new ImageLoadingListener() {

								@Override
								public void onLoadingStarted(String imageUri,
										View view) {
									// TODO Auto-generated method stub

								}

								@Override
								public void onLoadingFailed(String imageUri,
										View view, FailReason failReason) {
									if (mGifDrawable == null) {
										try {
											mGifDrawable = new GifDrawable(
													getResources(),
													R.drawable.index_gif);
											index_bg.setImageDrawable(mGifDrawable);
										} catch (NotFoundException e) {
											// TODO Auto-generated catch block
											e.printStackTrace();
										} catch (IOException e) {
											// TODO Auto-generated catch block
											e.printStackTrace();
										}
									} else {
										index_bg.setImageDrawable(mGifDrawable);
									}

								}

								@Override
								public void onLoadingComplete(String imageUri,
										View view, Bitmap loadedImage) {
									if (mGifDrawable != null) {
										mGifDrawable.recycle();
										mGifDrawable = null;
									}
								}

								@Override
								public void onLoadingCancelled(String imageUri,
										View view) {
									// TODO Auto-generated method stub

								}
							});
				} else {
					if (mGifDrawable == null) {
						try {
							mGifDrawable = new GifDrawable(getResources(),
									R.drawable.index_gif);
							index_bg.setImageDrawable(mGifDrawable);
						} catch (NotFoundException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						} catch (IOException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}
					} else {
						index_bg.setImageDrawable(mGifDrawable);
					}

				}

				if (mHomeData.getRecommendList() != null)
					bidList.addAll(mHomeData.getRecommendList());

				if (mHomeData.getQuickIn() != null
						&& mHomeData.getQuickIn().size() > 0) {
					Gson gson = new Gson();
					String json1 = gson.toJson(mQuickIn);
					String json2 = gson.toJson(mHomeData.getQuickIn());
					if (!json1.endsWith(json2)) {
						mQuickIn.clear();
						mQuickIn.addAll(mHomeData.getQuickIn());
						mQuickEntryAdapter.notifyDataSetChanged();
					}
					mQuickEntry.mQuickEntryGrid.setVisibility(View.VISIBLE);
					if (activities.size() > 0) {
						mBanner.setVisibility(View.VISIBLE);
					} else {
						mBanner.setVisibility(View.GONE);
					}
					mQuickEntry
							.setLayoutParams(new android.widget.AbsListView.LayoutParams(
									android.widget.AbsListView.LayoutParams.MATCH_PARENT,
									SystemUtils.dip2px(mCurActivity,
											activities.size() > 0 ? 314 : 210)));
				} else {
					mQuickEntry.mQuickEntryGrid.setVisibility(View.GONE);
					if (activities.size() > 0) {
						mBanner.setVisibility(View.VISIBLE);
					} else {
						mBanner.setVisibility(View.GONE);
					}
					mQuickEntry
							.setLayoutParams(new android.widget.AbsListView.LayoutParams(
									android.widget.AbsListView.LayoutParams.MATCH_PARENT,
									SystemUtils.dip2px(mCurActivity,
											activities.size() > 0 ? 104 : 1)));
				}
				mIndexListAdapter.notifyDataSetChanged();
				if (bidList.size() > 0) {
					reMoveGuanggao();
					addLastBid();
				} else {
				}
				if (mHomeData.getSaftydata() != null
						&& !TextUtils.isEmpty(mHomeData.getSaftydata()
								.getImageUrl())) {
					safe_img.setVisibility(View.VISIBLE);
					safe_img.setOnClickListener(new OnSingleClickListener() {

						@Override
						public void onSingleClick(View v) {
							if (!TextUtils.isEmpty(mHomeData.getSaftydata()
									.getToUrl())) {
								Intent intent = new Intent(mCurActivity,
										KKDWebActivity.class);
								intent.putExtra("url", mHomeData.getSaftydata()
										.getToUrl());
								startActivity(intent);
							}
						}
					});
				} else {
					safe_img.setVisibility(View.GONE);
				}
				// 如果有抽奖活动，将悬浮抽奖图标显示出来 ：以下
				if (mHomeData.getSpecialActivity() != null
						&& !TextUtils.isEmpty(mHomeData.getSpecialActivity()
								.getUrl())) {
					mSpecialActivityImg.setVisibility(View.VISIBLE);
					ImageLoader.getInstance().displayImage(
							mHomeData.getSpecialActivity().getImage(),
							mSpecialActivityImg,
							R.drawable.special_activity_img);
					mSpecialActivityImg
							.setOnTouchListener(new OnTouchListener() {

								@Override
								public boolean onTouch(View v, MotionEvent event) {
									switch (event.getAction()) {
									case MotionEvent.ACTION_DOWN:

										startX = event.getX();
										startY = event.getY();
										break;
									case MotionEvent.ACTION_UP:
									case MotionEvent.ACTION_CANCEL:
									case MotionEvent.ACTION_OUTSIDE:
										((HomeActivity) mCurActivity).isMovingSpecialActivityImg = false;
										break;
									case MotionEvent.ACTION_MOVE:
										float dertaX = event.getX() - startX;
										float dertaY = event.getY() - startY;
										if ((dertaX * dertaX + dertaY * dertaY) > 200) {
											startMoveSpecialActivityImg();
										}
										break;
									default:
										break;
									}
									return false;
								}
							});
					mSpecialActivityImg
							.setOnClickListener(new OnClickListener() {

								@Override
								public void onClick(View v) {
									if (mHomeData != null) {
										if (!TextUtils.isEmpty(mHomeData
												.getSpecialActivity().getUrl())) {
											SystemUtils.onEvent(
													"Regular_Award", 1);
											Intent intent = new Intent(
													mCurActivity,
													KKDWebActivity.class);
											intent.putExtra("url", mHomeData
													.getSpecialActivity()
													.getUrl());
											// intent.putExtra("url",
											// "http://192.168.1.82/pdfviewer/");
											// intent.putExtra("titleName",
											// mHomeData
											// .getSpecialActivity().getTitle());
											startActivity(intent);
										}
									}
									// Intent intent = new Intent(mCurActivity,
									// PdfReaderActivity.class);
									// startActivity(intent);
								}
							});
				} else {
					mSpecialActivityImg.setVisibility(View.GONE);
				}

				// 如果有抽奖活动，将悬浮抽奖图标显示出来 ：以上

				if (AppUtil.isConnect(BaseApplication.getInstance())) {
					index_bg.setVisibility(View.VISIBLE);
					img_null.setVisibility(View.GONE);
					tv_null.setVisibility(View.GONE);
					mListView.setVisibility(View.VISIBLE);
				}
				break;

			case DATA_FAIL:
				mScrollerLayout.clearState();
				String desc = (String) msg.obj;
				if (!TextUtils.isEmpty(desc))
					showToast(desc);
				break;
			case Const.NOTIFY_GOT_MYPROPERTY_SUCCESS_FLAG:
				loadPropertyCache();
				break;
			case Const.NOTIFY_HAVE_NOTICE:
				if (Notice.queryAllNotice() != null
						&& Notice.queryAllNotice().size() > 0) {
					Gson gson = new Gson();
					String json1 = gson.toJson(Notices);
					String json2 = gson.toJson(Notice.queryAllNotice());
					if (!json1.endsWith(json2)) {
						Notices.clear();
						Notices.addAll(Notice.queryAllNotice());
						mVFT.notifyDataSetChanged();
					}
					mVFT_RL.setVisibility(View.VISIBLE);

				} else {
					mVFT_RL.setVisibility(View.GONE);
					Notices.clear();
					mVFT.notifyDataSetChanged();
				}
				break;
			case SIGN_OK:
				linear_flag_sigining.setClickable(true);
				flag_updateSign = false;
				time_signin_success = System.currentTimeMillis();
				icon_happy_sign.clearAnimation();
				if (mSignTimer != null) {
					mSignTimer.cancel();
					mSignTimer = null;
				}
				if (mSignTimerTask != null) {
					mSignTimerTask.cancel();
					mSignTimerTask = null;
				}
				int addHappyCurrency = singInData.getAddHappyCurrency();// 本次签到增加快乐币数量
				PreferenceUtils.getInstance().setSignInFlag(mCurActivity, 1);

				sign_tv.setText(R.string.signed);
				icon_happy_sign.setImageResource(R.drawable.index_sign_gif);
				// 是否弹窗快乐币任务完成进度弹窗
				boolean popUp = singInData.getPopUp();
				// 签到完成状态，0未完成，1完成；
				int signInStatus = singInData.getSignInStatus();
				// 签到获取快乐币个数
				int signInCionSum = singInData.getSignInCionSum();
				// 签到优惠券金额
				long signIncouponAmount = singInData.getSignIncouponAmount();
				// 连续签到天数
				int days = singInData.getDays();
				// 分享邀请好友获得快乐币个数
				int inviteCionSum = singInData.getInviteCionSum();
				// 0未完成，1完成；
				int inviteStatus = singInData.getInviteStatus();
				// 投资完成状态，0未完成，1完成；
				int poiStatus = singInData.getPoiStatus();
				// 投资奖励快乐币个数
				int poiCionSum = singInData.getPoiCionSum();
				// 投资任务未完成提示最高奖励快乐币个数
				int poiMoreCionSum = singInData.getPoiMoreCionSum();
				// 邀请好友攻略Url
				String inviteStrategyUrl = singInData.getInviteStrategyUrl();
				// 快乐币任务全部完成获取快乐币总数
				int doubleAllSum = singInData.getDoubleAllSum();
				// 完成快乐币任务排名
				int customerSeat = singInData.getCustomerSeat();
				// 完成任务获得快乐币个数
				int doubleSum = singInData.getDoubleSum();
				// 完成快乐币任务翻倍的倍率
				String doubleRate = singInData.getDoubleRate();
				// 翻倍获取快乐币个数
				int doubleMisSum = singInData.getDoubleMisSum();
				// 快乐币任务url
				String coinMisUrl = singInData.getCoinMisUrl();
				// 是否可以补签 0：不可以，1：可以
				int isRepairSigninStatus = singInData.getIsRepairSigninStatus();
				// 补签信息
				ReSign reSign = singInData.getReSign();
				int reSignStatus = reSign.getReSignStatus();
				List<String> dataList = reSign.getDataList();
				if (popUp) {
					happyCoinCompleteProgressDialog(signInStatus,
							signInCionSum, signIncouponAmount, days,
							inviteCionSum, inviteStatus, poiStatus, poiCionSum,
							poiMoreCionSum, inviteStrategyUrl, doubleAllSum,
							customerSeat, doubleSum, doubleRate, doubleMisSum,
							coinMisUrl, isRepairSigninStatus);
				} else {
					String appsignRuleUrl = "";
					if (myProperty != null) {
						appsignRuleUrl = myProperty.getAppsignRuleUrl();
						mDialog_signin = DialogUtils.signInSuccessDialog4(
								getActivity(), singInData.getSignInDays(),
								singInData.getSumnum(),
								singInData.getSummaryFooter(), appsignRuleUrl,
								singInData.getCouponDesc(),
								singInData.getCouponAmount(), reSignStatus,
								dataList, new OnSingleClickListener() {

									@Override
									public void onSingleClick(View v) {
										switch (v.getId()) {
										case R.id.retroactive_bt:
											repairSignIn();
											if (singInData != null) {
												mDialog_signin.cancel();
												mDialog_signin = null;
											}
											break;
										}
									}
								});
					} else {
						// TODO: 资产信息为空的情况是异常情况，暂时不做处理
					}

				}
				break;
			case SIGN_NO:
				showToast(mCurActivity, mDesc);
				if (statusCode == 226) {
					sign_tv.setText(R.string.signed);
					// icon_happy_sign.setImageResource(R.drawable.index_sign_gif);
					icon_happy_sign.clearAnimation();
					if (mSignTimer != null) {
						mSignTimer.cancel();
						mSignTimer = null;
					}
					if (mSignTimerTask != null) {
						mSignTimerTask.cancel();
						mSignTimerTask = null;
					}
				}
				break;
			case REPAIRSIGNIN_OK:
				String sJson = (String) msg.obj;
				try {
					JSONObject rData = new JSONObject(sJson);
					String signDays = rData.getString("signDays");
					String signCoupon = rData.getString("signCoupon");
					if (TextUtils.isEmpty(signCoupon)) {
						showToast("补签成功\n" + signDays);
					} else {
						showToast("补签成功\n" + signDays + "\n" + signCoupon);
					}
				} catch (JSONException e) {
					e.printStackTrace();
				}
				break;
			case REPAIRSIGNIN_NO:
				String rDesc = (String) msg.obj;
				showToast(rDesc);
				break;

			case SIGN_ANIMATION:
				icon_happy_sign.startAnimation(signAnimation);
				break;
			default:
				break;
			}
		}

	};

	@Override
	public void onAttach(Activity activity) {
		super.onAttach(activity);

		mCurActivity = (HomeActivity) activity;
		// mFooterListView = new ListView(mCurActivity);
		// mFooterListView.setBackgroundResource(R.color.white);
		// mFooterListView.setPadding(0, 0, 0,
		// SystemUtils.dip2px(mCurActivity, 10));
		// mFooterListView.setDividerHeight(0);
		// mFooterListView.setSelector(R.color.transparent);
		NotifyDispatcher.getInstance().registerNotifyHandler(mHandle);
		// rAllConfig = ((HomeActivity) mCurActivity).mAllConfig;
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		mContentView = inflater.inflate(R.layout.index_fragment, container,
				false);
		initUI(mContentView);
		initSignAnimation();
		return mContentView;
	}

	/**
	 * 初始化签到动画
	 */
	private void initSignAnimation() {
		signAnimation = AnimationUtils.loadAnimation(mCurActivity,
				R.anim.index_sign_anim);
		signAnimation2 = AnimationUtils.loadAnimation(mCurActivity,
				R.anim.index_sign_anim2);
		signAnimation.setAnimationListener(new AnimationListener() {

			@Override
			public void onAnimationStart(Animation animation) {

			}

			@Override
			public void onAnimationRepeat(Animation animation) {

			}

			@Override
			public void onAnimationEnd(Animation animation) {
				icon_happy_sign.startAnimation(signAnimation2);
			}
		});
	}

	/**
	 * 开启签到动画
	 */
	private void startSignAnimation() {
		if (mSignTimer != null) {
			mSignTimer.cancel();
			mSignTimer = null;
		}
		if (mSignTimerTask != null) {
			mSignTimerTask.cancel();
			mSignTimerTask = null;
		}
		mSignTimer = new Timer();
		mSignTimerTask = new TimerTask() {

			@Override
			public void run() {
				mHandle.sendEmptyMessage(SIGN_ANIMATION);
			}
		};
		mSignTimer.schedule(mSignTimerTask, 0, 3000);
	}

	/**
	 * initUI:(初始化UI). <br/>
	 * 
	 * @author askzhao
	 */
	private void initUI(View view) {

		mScrollHeadView = new IndexScrollHeader(mCurActivity);
		mTitleBar = (RelativeLayout) view.findViewById(R.id.title_bar);
		mScrollerLayout = (ScrollerLayout) view
				.findViewById(R.id.scroller_layout);
		mScrollerLayout.addTopView(mScrollHeadView);
		mListView = (ListView) view.findViewById(R.id.regular_lv);
		mIndexListAdapter = new IndexListAdapter(mCurActivity, bidList);
		mSpecialActivityImg = (ImageView) view
				.findViewById(R.id.special_activity_Img);
		img_null = (ImageView) view.findViewById(R.id.img_null);
		tv_null = (TextView) view.findViewById(R.id.tv_null);

		mHeadView = new HomeHeadView(mCurActivity);
		no_Index_header_bg = (ImageView) mHeadView
				.findViewById(R.id.index_header_bg);
		index_header_bg = (ImageView) view.findViewById(R.id.index_header_bg);
		index_header_bg2 = (ImageView) view.findViewById(R.id.index_header_bg2);
		title_bar_rl = (RelativeLayout) mHeadView
				.findViewById(R.id.title_bar_rl);
		index_bg = (ImageView) view.findViewById(R.id.index_bg);
		icon_happy_sign = (ImageView) mHeadView
				.findViewById(R.id.icon_happy_sign);
		myproperty_header = (RoundImageView) view
				.findViewById(R.id.myproperty_header);
		myproperty_header.setOnClickListener(new OnSingleClickListener() {

			@Override
			public void onSingleClick(View v) {
				if (PreferenceUtils.getInstance().getLogin(getActivity()) == 0) {
					Intent intent = new Intent(getActivity(), MyActivity.class);
					startActivityForResult(intent, 400);
				} else {
					Intent intent = new Intent(mCurActivity,
							LoginActivity.class);
					startActivity(intent);
				}

			}
		});

		earnings_tv = (CountViewFloat) mHeadView.findViewById(R.id.earnings_tv);
		earnings_tv.setDecimalFormat(new DecimalFormat("###,##0.00"));
		earnings_tv.setOnClickListener(new OnSingleClickListener() {

			@Override
			public void onSingleClick(View v) {
				Intent intent = new Intent(getActivity(),
						MyIncomeActivity.class);
				startActivity(intent);
			}
		});

		mWaveView = (WaveView) mHeadView.findViewById(R.id.wave_view);
		// mWaveView.start();
		mHeadView.setLayoutParams(new android.widget.AbsListView.LayoutParams(
				android.widget.AbsListView.LayoutParams.MATCH_PARENT,
				android.widget.AbsListView.LayoutParams.WRAP_CONTENT));

		mQuickEntry = new HomeQuickEntryView(mCurActivity);
		mBanner = (CycleBannerView) mQuickEntry
				.findViewById(R.id.cycle_banner_view);
//		mBanner.setDots(R.drawable.page_focused2, R.drawable.page_unfocused2);
//		mBanner.setImgSources(activities);
//		LayoutParams layoutParams = (LayoutParams) mBanner.getLayoutParams();
//		layoutParams.width = LayoutParams.MATCH_PARENT;
//		layoutParams.height = SystemUtils.dip2px(mCurActivity, 94);
//		mBanner.setLayoutParams(layoutParams);
		mBanner.setImages(activities)
        .setImageLoader(new KBannerImagLoader())
        .setOnBannerClickListener(new OnBannerClickListener() {
			
			@Override
			public void OnBannerClick(int position) {
				try {
					String url = activities.get(position).getUrl();
					if (!TextUtils.isEmpty(url)) {
						SystemUtils.onEvent("Regular_Banner_" + (position + 1), 1);
						Intent intent = new Intent(mCurActivity, KKDWebActivity.class);
						intent.putExtra("useTitleName", true);
						intent.putExtra("titleName", activities.get(position).getTitle());
						intent.putExtra("desc", activities.get(position).getDesc());
						intent.putExtra("url", url);
						intent.putExtra("shareUrl", activities.get(position)
								.getShareUrl());
						startActivity(intent);
					}
				} catch (Exception e1) {
					e1.printStackTrace();
				}
			}
		})
        .start();
		mQuickEntryAdapter = new QuickEntryAdapter(mCurActivity, mQuickIn);
		mQuickEntry.setAdapter(mQuickEntryAdapter);
		safe_img = (RelativeLayout) mHeadView.findViewById(R.id.safe_img);
		mVFT = (VerticalFlipTextView) mHeadView
				.findViewById(R.id.index_notice_flip_text);
		mVFT_RL = (RelativeLayout) mHeadView
				.findViewById(R.id.index_notice_flip_rl);
		mVFT.setNotices(Notices);
		mVFT_RL.setVisibility(View.GONE);
		mListView.addHeaderView(mHeadView);
		mListView.addHeaderView(mQuickEntry);
		GuangGao = RelativeLayout.inflate(mCurActivity,
				R.layout.home_guanggao_layout, null);
		mListView.addHeaderView(GuangGao);
		// mIndexFooterListListAdapter = new IndexFooterListListAdapter(
		// mCurActivity, activities);

		// mFooterListView.setAdapter(mIndexFooterListListAdapter);
		// mListView.addFooterView(mFooterListView);
		mListView.setAdapter(mIndexListAdapter);
		mListView.setOnScrollListener(new OnScrollListener() {

			@Override
			public void onScrollStateChanged(AbsListView view, int scrollState) {
			}

			@Override
			public void onScroll(AbsListView view, int firstVisibleItem,
					int visibleItemCount, int totalItemCount) {
				// if (firstVisibleItem == 0) {
				// if (mListView.getChildAt(0) == null)
				// return;
				// float top = Math.abs(mListView.getChildAt(0).getTop());
				// // float alpha = top / mHeadView.getHeight();
				// // if (alpha > 0.1) {
				// // title_bar_rl.setAlpha(alpha);
				// // title_bar_rl.setVisibility(View.VISIBLE);
				// // } else {
				// // title_bar_rl.setVisibility(View.GONE);
				// // }
				// LayoutParams parms = (LayoutParams) index_bg
				// .getLayoutParams();
				// parms.topMargin = (int) -top;
				// index_bg.setLayoutParams(parms);
				// // index_bg.setPadding(0, (int) -top, 0, (int) -top);
				// } else {
				// // title_bar_rl.setAlpha(1);
				// // title_bar_rl.setVisibility(View.VISIBLE);
				// LayoutParams parms = (LayoutParams) index_bg
				// .getLayoutParams();
				// parms.topMargin = (int) 0;
				// index_bg.setLayoutParams(parms);
				// }
				LogUtil.e("TAG", "IndexFragment--------->ListView-->onScroll");
				LogUtil.e("TAG", "downFlag--------->" + downFlag);
				if (downFlag) {
					int scrollY = getScrollY();
					LogUtil.e("TAG", "scrollY--->" + scrollY);
					if (scrollY > 0) {
						if (PreferenceUtils.getInstance().getLogin(
								getActivity()) != 0) {
							no_Index_header_bg.clearAnimation();
							myproperty_header.clearAnimation();
							no_Index_header_bg.setAlpha(0.0f);
							index_header_bg2.setAlpha(0.0f);
						} else {
							index_header_bg.setAlpha(0.0f);
							index_header_bg2.setAlpha(0.0f);
						}
						if (SystemUtils.px2dip(mCurActivity, scrollY / 2) < 40) {
							myproperty_header.setTranslationY(-scrollY / 2);
							myproperty_header.setScaleX(Math.abs((float) (1 - SystemUtils
									.px2dip(mCurActivity, scrollY / 2) * 0.0127)));
							myproperty_header.setScaleY(Math.abs((float) (1 - SystemUtils
									.px2dip(mCurActivity, scrollY / 2) * 0.0127)));
						} else {
							myproperty_header.setTranslationY(-SystemUtils
									.dip2px(mCurActivity, 40));
							myproperty_header.setScaleX(0.5f);
							myproperty_header.setScaleY(0.5f);
						}

						if (scrollY < SystemUtils.dip2px(mCurActivity, 90)) {
							alphaColor = (float) (0.01 / Math.rint(SystemUtils
									.dip2px(mCurActivity, 90) * 0.01));
							mTitleBar.setAlpha((float) (scrollY * alphaColor));
						} else {
							mTitleBar.setAlpha(1);
						}
					} else {
						if (PreferenceUtils.getInstance().getLogin(
								getActivity()) == 0) {
							no_Index_header_bg.clearAnimation();
							myproperty_header.clearAnimation();
							index_header_bg.setAlpha(1.0f);
						} else {
							if (index_header_bg_Animation == null) {
								index_header_bg_Animation = startStripeAnimation(true);
							}
							no_Index_header_bg
									.startAnimation(index_header_bg_Animation);
							if (myproperty_header_Animation == null) {
								myproperty_header_Animation = AnimationUtils
										.loadAnimation(mCurActivity,
												R.anim.index_head_flip);
							}
							myproperty_header
									.startAnimation(myproperty_header_Animation);
							no_Index_header_bg.setAlpha(1.0f);
						}
						index_header_bg2.setAlpha(1.0f);
						myproperty_header.setTranslationY(0);
						index_header_bg.setTranslationY(0);
						index_header_bg2.setTranslationY(0);
						myproperty_header.setScaleX(1);
						myproperty_header.setScaleY(1);
						mTitleBar.setAlpha(0.0f);
					}

				}

			}
		});
		mScrollerLayout.setScrollStateProvider(new ScrollStateProvider() {

			@Override
			public boolean canPullUp() {
				// TODO Auto-generated method stub
				return false;
			}

			@Override
			public boolean canPullDown() {

				if (mListView.getFirstVisiblePosition() == 0
						&& mListView.getChildAt(0).getTop() == 0)
					return true;
				return false;
			}
		});
		mScrollerLayout.setOnPullListener(new OnPullListener() {

			@Override
			public void onPullUp(float top) {

			}

			@Override
			public void onPullStateChange(byte state) {
				mScrollHeadView.changeHeaderViewByState(state);
				switch (state) {
				case ScrollerLayout.STATUS_IDLE:// 空闲状态
					mScrollHeadView.setVisibility(View.GONE);
					mWaveView.setVisibility(View.GONE);
					LogUtil.e("TAG",
							"IndexFragment--------ScrollerLayout.STATUS_IDLE");
					myproperty_header.setTranslationY(0);
					if (PreferenceUtils.getInstance().getLogin(mCurActivity) == 0) {
						index_header_bg.setTranslationY(0);
					}
					index_header_bg2.setTranslationY(0);
					downFlag = true;
					break;
				case ScrollerLayout.STATUS_PULL_DOWN:// 下拉：不满足hold条件
					mScrollHeadView.setVisibility(View.VISIBLE);
					mWaveView.setVisibility(View.VISIBLE);
					// mWaveView.initializeWave(1.2f, 30f, 0.1f);
					LogUtil.e("TAG",
							"IndexFragment--------ScrollerLayout.STATUS_PULL_DOWN");
					break;
				case ScrollerLayout.STATUS_PULL_UP:// 上拉：不满足hold条件
					LogUtil.e("TAG",
							"IndexFragment--------ScrollerLayout.STATUS_PULL_UP");
					break;
				case ScrollerLayout.STATUS_UP_HOLD:// 上拉后等待状态
					LogUtil.e("TAG",
							"IndexFragment--------ScrollerLayout.STATUS_UP_HOLD");
					break;
				case ScrollerLayout.STATUS_DOWN_HOLD:// 下拉后等待状态
					mCurActivity.mymanage();
					homeQueset();
					LogUtil.e("TAG",
							"IndexFragment--------ScrollerLayout.STATUS_DOWN_HOLD");
					break;
				case ScrollerLayout.STATUS_ANIMATING:// 回弹动画状态
					LogUtil.e("TAG",
							"IndexFragment--------ScrollerLayout.STATUS_ANIMATING");
					break;
				case ScrollerLayout.STATUS_PULL_DOWN_ENABLE:// 下拉：满足hold条件，松开将hold
					// mWaveView.initializeWave(1.8f, 30f, 0.2f);
					LogUtil.e("TAG",
							"IndexFragment--------ScrollerLayout.STATUS_PULL_DOWN_ENABLE");
					break;
				case ScrollerLayout.STATUS_PULL_UP_ENABLE: // 上拉：满足hold条件，松开将hold
					LogUtil.e("TAG",
							"IndexFragment--------ScrollerLayout.STATUS_PULL_UP_ENABLE");
					break;
				default:
					break;
				}
			}

			@Override
			public void onPullDown(final float top) {
				float derta = top / mScrollHeadView.getHeight();
				int length = SystemUtils.dip2px(mCurActivity, 1);
				// int alpha = (int) (256*(1.5-derta));
				// alpha = alpha>255?255:alpha;
				mWaveView.setAboveWaveColor(0xffffffff, 255);
				mWaveView.setBlowWaveColor(0xffffffff, 127);
				mWaveView.initializeWave(1f + 1f * derta, length + derta
						* length * 5 * derta, 0.2f, length + derta * length * 5
						* derta);
				// android.view.ViewGroup.LayoutParams parms = index_bg
				// .getLayoutParams();
				// parms.height = (int) (SystemUtils.dip2px(mCurActivity, 220) +
				// top);
				// index_bg.setLayoutParams(parms);
				LogUtil.e("TAG",
						"IndexFragment-------->ScrollerLayout-->onPullDown");
				LogUtil.e("TAG", "top-------->" + top);
				if (top < 10) {
					myproperty_header.setTranslationY(0);
					if (PreferenceUtils.getInstance().getLogin(mCurActivity) == 0) {
						index_header_bg.setTranslationY(0);
					} else {
						// android.widget.RelativeLayout.LayoutParams param =
						// (LayoutParams) index_header_bg
						// .getLayoutParams();
						// param.topMargin = (int) (SystemUtils.dip2px(
						// mCurActivity, 46));
						// index_header_bg.setLayoutParams(param);
					}
					index_header_bg2.setTranslationY(0);
				} else if (top < 136) {
					myproperty_header.setTranslationY(top);
					if (PreferenceUtils.getInstance().getLogin(mCurActivity) == 0) {
						index_header_bg.setTranslationY(top);
					} else {
						// android.widget.RelativeLayout.LayoutParams param =
						// (LayoutParams) index_header_bg
						// .getLayoutParams();
						// param.topMargin = (int) (SystemUtils.dip2px(
						// mCurActivity, 46) + top);
						// index_header_bg.setLayoutParams(param);
					}
					index_header_bg2.setTranslationY(top);
					downFlag = true;
				} else {
					myproperty_header.setTranslationY(top);
					if (PreferenceUtils.getInstance().getLogin(mCurActivity) == 0) {
						index_header_bg.setTranslationY(top);
					} else {
						// android.widget.RelativeLayout.LayoutParams param =
						// (LayoutParams) index_header_bg
						// .getLayoutParams();
						// param.topMargin = (int) (SystemUtils.dip2px(
						// mCurActivity, 46) + top);
						// index_header_bg.setLayoutParams(param);
					}
					index_header_bg2.setTranslationY(top);
					downFlag = false;
				}

			}
		});

		// mTurnTv = (CountViewFloat)
		// profit_line.findViewById(R.id.totle_turn_tv);
		// mTurnTv.setDecimalFormat(new DecimalFormat("#,###.00"));
		// mProfitTv = (CountViewFloat) profit_line
		// .findViewById(R.id.totle_profit_tv);
		// mProfitTv.setDecimalFormat(new DecimalFormat("#,###.00"));

		linear_flag_sigining = (LinearLayout) view
				.findViewById(R.id.linear_flag_sigining);
		sign_tv = (TextView) view.findViewById(R.id.sign_tv);
		triangle = (RelativeLayout) view.findViewById(R.id.triangle);
		login_bt = (Button) view.findViewById(R.id.login_bt);
		login_bt.setOnClickListener(new OnSingleClickListener() {

			@Override
			public void onSingleClick(View v) {
				Intent intent = new Intent(mCurActivity, LoginActivity.class);
				startActivity(intent);
			}
		});
		linear_flag_sigining.setOnClickListener(new OnSingleClickListener() {

			@Override
			public void onSingleClick(View v) {
				if (!sign_tv.getText().toString().equals("签到")) {
					SystemUtils.onEvent("Account_UnCheckIN", 1);
					Intent intent = new Intent(getActivity(),
							SignActivity.class);
					startActivity(intent);
				} else {
					signIn();
				}
			}
		});
		loadCache();

		if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
			android.widget.RelativeLayout.LayoutParams parms = (LayoutParams) title_bar_rl
					.getLayoutParams();
			parms.topMargin = 0;
			title_bar_rl.setLayoutParams(parms);
		}
	}

	private void reMoveGuanggao() {
		mListView.removeHeaderView(GuangGao);
	}

	private void addLastBid() {
		if (BidPast == null) {
			BidPast = RelativeLayout.inflate(mCurActivity,
					R.layout.last_bid_item, null);
			BidPast.findViewById(R.id.welfare).setOnClickListener(
					new OnSingleClickListener() {

						@Override
						public void onSingleClick(View v) {
							Intent intent = new Intent(mCurActivity,
									WelfareActivity.class);
							startActivity(intent);
						}
					});
			BidPast.findViewById(R.id.financial_plan).setOnClickListener(
					new OnSingleClickListener() {

						@Override
						public void onSingleClick(View v) {
							Intent intent = new Intent(mCurActivity,
									FinancialPlanParticularsActivity.class);
							startActivity(intent);
						}
					});
			BidPast.findViewById(R.id.selected_bid).setOnClickListener(
					new OnSingleClickListener() {

						@Override
						public void onSingleClick(View v) {
							Intent intent = new Intent(mCurActivity,
									SelectedBidActivity.class);
							startActivity(intent);
						}
					});
			mListView.addFooterView(BidPast);
		}
	}

	public void signIn() {
		if (PreferenceUtils.getInstance().getLogin(getActivity()) != 0) {
			Intent intent = new Intent(mCurActivity, LoginActivity.class);
			startActivity(intent);
			return;
		}
		linear_flag_sigining.setClickable(false);
		KkdHttpMagager.getInstance().getSignManager(SingInData.class,
				new HttpCallBack() {

					@Override
					public void onSuccess(int statusCode, Object responseBody) {
						singInData = (SingInData) responseBody;
						mHandle.sendEmptyMessage(SIGN_OK);
					}

					@Override
					public void onFailure(int statusCode, String desc) {
						IndexFragment.this.statusCode = statusCode;
						IndexFragment.this.mDesc = desc;
						linear_flag_sigining.setClickable(true);
					}
				});
	}

	public void showToast(Activity acitivity, String hintLanguage) {
		AppUtil.makeToastForCustomer(acitivity, hintLanguage);
	}

	public int getScrollY() {
		View c = mListView.getChildAt(0);
		if (c == null) {
			return 0;
		}

		int firstVisiblePosition = mListView.getFirstVisiblePosition();
		int top = c.getTop();
		int headerHeight = 0;
		// if (firstVisiblePosition >= 1) {
		// // headerHeight = mPlaceHolderView.getHeight();
		// headerHeight = mRegularLv.getHeaderViewsCount();
		// }
		if (top == 0 && firstVisiblePosition == 0) {
			return headerHeight - c.getHeight();
		}

		return -top + firstVisiblePosition * c.getHeight() + headerHeight;
	}

	/**
	 * loadCache:(这里用一句话描述这个方法的作用). <br/>
	 * 
	 * @author askzhao
	 */
	private void loadPropertyCache() {
		String json = PreferenceUtils.getInstance().getMyproperty(mCurActivity);
		if (!TextUtils.isEmpty(json)) {

			Gson gson = new Gson();
			AllAccountInfo mAllAccountInfo = gson.fromJson(json,
					AllAccountInfo.class);
			myProperty = mAllAccountInfo.getOtherData();
			if (myProperty != null) {
				DecimalFormat df = new DecimalFormat("###,##0.00");
				String totalIncome = df.format(myProperty.getTotalIncome());
				earnings_tv.setText(totalIncome);
				earnings_tv.showNumberWithAnimation(0,
						(float) myProperty.getTotalIncome(), 300);
				int signInFlag = myProperty.getSignInFlag();
				PreferenceUtils.getInstance().setSignInFlag(mCurActivity,
						signInFlag);
				long curTime = System.currentTimeMillis();
				if (flag_updateSign || curTime - time_signin_success > 2000) {
					if (signInFlag == 0) {
						sign_tv.setText("签到");
						startSignAnimation();
					} else if (signInFlag == 1) {
						sign_tv.setText(R.string.signed);
						icon_happy_sign.clearAnimation();
						if (mSignTimer != null) {
							mSignTimer.cancel();
							mSignTimer = null;
						}
						if (mSignTimerTask != null) {
							mSignTimerTask.cancel();
							mSignTimerTask = null;
						}
					}
				}
				flag_updateSign = true;
			} else {
				earnings_tv.setText("0.00");
			}

		} else {
			earnings_tv.setText("0.00");
		}
	}

	private void loadCache() {
		loadPropertyCache();

		Gson gson = new Gson();

		String cache = PreferenceUtils.getInstance().getHomeData(mCurActivity);
		if (!TextUtils.isEmpty(cache)) {

			Home home = gson.fromJson(cache, Home.class);
			mHomeData = home.getData();
			if (mHomeData != null)
				mHandle.sendEmptyMessage(DATA_OK);
		} else {

			mListView.setVisibility(View.VISIBLE);
			index_bg.setVisibility(View.VISIBLE);
			mHomeData = new HomeData();
			mHomeData.setQuickIn(new ArrayList<QuickIn>());
			for (int i = 0; i < 6; i++) {
				QuickIn qi = new QuickIn();
				mHomeData.getQuickIn().add(qi);
			}
			mHandle.sendEmptyMessage(DATA_OK);
		}
		homeQueset();

	}

	private AnimationSet startStripeAnimation(final boolean repeat) {
		ScaleAnimation scaleAnimation = new ScaleAnimation(1f, 2f, 1f, 2f,
				Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,
				0.5f);
		AlphaAnimation alphaAnimation = new AlphaAnimation(1f, 0f);
		if (repeat) {
			scaleAnimation.setRepeatCount(Animation.INFINITE);
			alphaAnimation.setRepeatCount(Animation.INFINITE);
		}
		AnimationSet animationSet = new AnimationSet(false);
		animationSet.addAnimation(scaleAnimation);
		animationSet.addAnimation(alphaAnimation);
		animationSet.setRepeatMode(Animation.REVERSE);
		animationSet.setDuration(1000);
		return animationSet;
	}

	private Animation index_header_bg_Animation;
	private Animation myproperty_header_Animation;

	@Override
	public void onResume() {
		super.onResume();
		if (PreferenceUtils.getInstance().getLogin(getActivity()) == 0) {
			triangle.setVisibility(View.VISIBLE);
			login_bt.setVisibility(View.GONE);
			linear_flag_sigining.setVisibility(View.VISIBLE);
			no_Index_header_bg.setVisibility(View.GONE);
			index_header_bg.setVisibility(View.VISIBLE);
			index_header_bg.clearAnimation();
			myproperty_header.clearAnimation();
		} else {
			triangle.setVisibility(View.GONE);
			login_bt.setVisibility(View.VISIBLE);
			linear_flag_sigining.setVisibility(View.GONE);
			no_Index_header_bg.setVisibility(View.VISIBLE);
			index_header_bg.setVisibility(View.GONE);
			if (index_header_bg_Animation == null) {
				index_header_bg_Animation = startStripeAnimation(true);
			}
			no_Index_header_bg.startAnimation(index_header_bg_Animation);
			if (myproperty_header_Animation == null) {
				myproperty_header_Animation = AnimationUtils.loadAnimation(
						mCurActivity, R.anim.index_head_flip);
			}
			myproperty_header.startAnimation(myproperty_header_Animation);
		}

		if (Notice.queryAllNotice() != null
				&& Notice.queryAllNotice().size() > 0) {
			Gson gson = new Gson();
			String json1 = gson.toJson(Notices);
			String json2 = gson.toJson(Notice.queryAllNotice());
			if (!json1.endsWith(json2)) {
				Notices.clear();
				Notices.addAll(Notice.queryAllNotice());
				mVFT.notifyDataSetChanged();
			}
			mVFT_RL.setVisibility(View.VISIBLE);
		} else {
			mVFT_RL.setVisibility(View.GONE);
			Notices.clear();
			mVFT.notifyDataSetChanged();
		}

		if (PreferenceUtils.getInstance().getSignInFlag(mCurActivity) == 1) {
			sign_tv.setText("已签");
			icon_happy_sign.setImageResource(R.drawable.index_sign_gif);
			icon_happy_sign.clearAnimation();
			if (mSignTimer != null) {
				mSignTimer.cancel();
				mSignTimer = null;
			}
			if (mSignTimerTask != null) {
				mSignTimerTask.cancel();
				mSignTimerTask = null;
			}
		} else {
			// icon_happy_sign.startAnimation(signAnimation);//
			sign_tv.setText("签到");
			startSignAnimation();
		}
		String url = PreferenceUtils.getInstance().getHeadUrl(mCurActivity);
		if (TextUtils.isEmpty(url)) {
			myproperty_header.setImageResource(R.drawable.myproperty_header);
		} else {
			ImageLoader.getInstance().displayImage(url, myproperty_header,
					R.drawable.myproperty_header);
		}
		loadPropertyCache();
		homeQueset();
		if (DialogUtils.mRegularSelectorAdapter != null)
			DialogUtils.mRegularSelectorAdapter
					.setCurPosition(productTypePosition);
	}

	private String productType = "";
	private int productTypePosition = 0;

	public void homeQueset() {
		KkdHttpMagager.getInstance().getHomeManager(productType, Home.class,
				new HttpCallBack() {

					@Override
					public void onSuccess(int statusCode, Object res) {
						try {
							Home home = (Home) res;
							mHomeData = home.getData();
							Gson gson = new Gson();
							PreferenceUtils.getInstance().setHomeData(
									mCurActivity, gson.toJson(home));
							if (mHomeData != null)
								mHandle.sendEmptyMessage(DATA_OK);

						} catch (Exception e) {
							e.printStackTrace();
							Message msg = new Message();
							msg.what = DATA_FAIL;
							String desc = "网络错误";
							Home home = (Home) res;
							desc = home.getDesc();
							msg.obj = desc;
							mHandle.sendMessage(msg);
							mHandle.sendEmptyMessage(DATA_FAIL);
						}
					}

					@Override
					public void onFailure(int statusCode, String responseBody) {
						Message msg = new Message();
						msg.what = DATA_FAIL;
						String desc = responseBody;
						msg.obj = desc;
						mHandle.sendMessage(msg);
					}
				});
	}

	private void startMoveSpecialActivityImg() {
		if (mCurActivity instanceof HomeActivity) {
			((HomeActivity) mCurActivity).isMovingSpecialActivityImg = true;
		}

	}

	/**
	 * onMovingSpecialActivityImg:(首页特殊活动，红包移动监控). <br/>
	 * 
	 * @author askzhao
	 * @param event
	 * @return
	 */
	public boolean onMovingSpecialActivityImg(MotionEvent event) {
		switch (event.getAction()) {
		case MotionEvent.ACTION_MOVE:
			int w = SystemUtils.dip2px(mCurActivity, 27);
			int h = SystemUtils.dip2px(mCurActivity, 31);
			float x = event.getX() - w;
			float y = event.getY() - h;
			if (x < 0)
				x = 0;
			if (x > mContentView.getWidth() - 2 * w)
				x = mContentView.getWidth() - 2 * w;
			if (y < 0)
				y = 0;
			if (y > mContentView.getHeight() - 2 * h)
				y = mContentView.getHeight() - 2 * h;
			mSpecialActivityImg.setX(x);
			mSpecialActivityImg.setY(y);
			break;
		case MotionEvent.ACTION_UP:
		case MotionEvent.ACTION_CANCEL:
		case MotionEvent.ACTION_OUTSIDE:
			if (mCurActivity instanceof HomeActivity) {
				((HomeActivity) mCurActivity).isMovingSpecialActivityImg = false;
			}
			int screenWith = SystemUtils.getScreenWidth(mCurActivity);
			int w1 = SystemUtils.dip2px(mCurActivity, 27);
			float x1 = event.getX() - w1;
			if (x1 < screenWith / 2)
				x1 = 0;
			if (x1 >= screenWith / 2)
				x1 = mContentView.getWidth() - 2 * w1;
			mSpecialActivityImg.setX(x1);
			break;
		default:
			if (mCurActivity instanceof HomeActivity) {
				((HomeActivity) mCurActivity).isMovingSpecialActivityImg = false;
			}
			break;
		}
		return false;
	}

	private void showToast(String hintLanguage) {
		AppUtil.makeToastForCustomer(getActivity(), hintLanguage);
	}

	/***********
	 * 快乐币任务完成进度Dialog
	 ***********/
	public void happyCoinCompleteProgressDialog(int signInStatus,
			int signInCionSum, long signIncouponAmount, int signDays,
			int inviteCionSum, int inviteStatus, int poiStatus, int poiCionSum,
			int poiMoreCionSum, String inviteStrategyUrl, int doubleAllSum,
			int customerSeat, int doubleSum, String doubleRate,
			int doubleMisSum, String coinMisUrl, int isRepairSigninStatus) {
		if (happyCoinCompleteProgressDialog != null) {
			happyCoinCompleteProgressDialog.cancel();
			happyCoinCompleteProgressDialog = null;
		}
		happyCoinCompleteProgressDialog = DialogUtils
				.happyCoinCompleteProgressDialog(getActivity(), true,
						signInStatus, signInCionSum, signIncouponAmount,
						signDays, 1, inviteCionSum, inviteStatus, poiStatus,
						poiCionSum, poiMoreCionSum, inviteStrategyUrl,
						doubleAllSum, customerSeat, doubleSum, doubleRate,
						doubleMisSum, coinMisUrl, isRepairSigninStatus);
		happyCoinCompleteProgressDialog.show();
	}

	// 补签接口
	public void repairSignIn() {
		KkdHttpMagager.getInstance().repairSignIn(String.class,
				new HttpCallBack() {

					@Override
					public void onSuccess(int statusCode, Object responseBody) {
						Message msg = new Message();
						msg.what = REPAIRSIGNIN_OK;
						msg.obj = responseBody;
						mHandle.sendMessage(msg);
					}

					@Override
					public void onFailure(int statusCode, String desc) {
						Message msg = new Message();
						msg.what = REPAIRSIGNIN_NO;
						msg.obj = desc;
						mHandle.sendMessage(msg);

					}
				});
	}

	@Override
	public void onDestroy() {
		super.onDestroy();
		NotifyDispatcher.getInstance().unRegisterNotifyHandler(mHandle);
		if (happyCoinCompleteProgressDialog != null) {
			happyCoinCompleteProgressDialog.cancel();
			happyCoinCompleteProgressDialog = null;
		}
		if (mDialog_signin != null) {
			mDialog_signin.cancel();
			mDialog_signin = null;
		}
		if (mSignTimer != null) {
			mSignTimer.cancel();
			mSignTimer = null;
		}
		if (mSignTimerTask != null) {
			mSignTimerTask.cancel();
			mSignTimerTask = null;
		}
	}

	public void ScrollToTop() {
		if (mListView != null) {
			mListView.setSelection(0);
		}

	}
}
